home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / sozo2 / scsrc20.lzh / TOP.LZH / TOP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-22  |  3.9 KB  |  186 lines

  1. /* Copyright (c) 1988,1991 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14.  
  15. #include "inst.h"
  16. #include "opcodes.h"
  17.  
  18. #define    DEBUG        /* enable debug code */
  19.  
  20. #ifdef    DEBUG
  21. #define    DBG(x)        if (debug) { x; }
  22. #else
  23. #define    DBG(x)
  24. #endif
  25.  
  26. #ifndef    void
  27. #define    void    int
  28. #endif
  29.  
  30. /*
  31.  * Basic defines and declarations for the optimizer.
  32.  */
  33.  
  34. typedef    int    bool;
  35.  
  36. #ifndef    FALSE
  37. #define    FALSE    0
  38. #define    TRUE    1
  39. #endif
  40.  
  41. /*
  42.  * Basic Block:
  43.  *
  44.  * References a linked list of instructions that make up the block.
  45.  * Each block can be exited via one of two branches, which are
  46.  * represented by pointers to two other blocks, or null.
  47.  */
  48. struct    block {
  49.     int    flags;            /* flags relating to this block */
  50.     int    ref;            /* # of references to this block */
  51.     int    bcode;            /* type of exiting branch */
  52.     char    *name;            /* symbol name that starts the block */
  53.  
  54.     struct    inst    *first,        /* first instruction in block */
  55.             *last;        /* last instruction in block */
  56.  
  57.     /*
  58.      * Execution traversals
  59.      */
  60.     struct    block    *bcond,        /* conditional branch (or NULL) */
  61.             *bfall;        /* "fall through" branch */
  62.  
  63.     /*
  64.      * Logical traversals
  65.      */
  66.     struct    block    *chain;        /* links all blocks together */
  67.     struct    block    *next;        /* next block in the file */
  68.  
  69.     /*
  70.      * Information for data-flow analysis
  71.      */
  72.     int    rref;            /* registers ref'd before set */
  73.     int    rset;            /* registers modified by block */
  74. };
  75.  
  76. typedef    struct block    BLOCK;
  77. typedef    struct inst    INST;
  78.  
  79. /*
  80.  * Block flags
  81.  */
  82.  
  83. #define    B_GLOBAL    0x01        /* is the block's symbol global? */
  84. #define    B_TOUCHED    0x02        /* used in traversals */
  85. #define    B_LABEL        0x04        /* the block needs a label */
  86. #define    B_ISREACHED    0x08        /* block IS reached (for switches) */
  87. #define    B_RET        0x10        /* block terminates with a 'return' */
  88. #define    B_MARK        0x20        /* temporary 'touched' mark */
  89.  
  90. /*
  91.  * Global data
  92.  */
  93.  
  94. extern    FILE    *ifp, *ofp;        /* input and output file pointers */
  95.  
  96. /*
  97.  * Option flags set in main
  98.  */
  99. extern    bool    debug;
  100. extern    bool    do_peep;        /* enable peephole opt. */
  101. extern    bool    do_brev;        /* enable branch reversals */
  102. extern    bool    do_regs;        /* enable "registerizing" */
  103. extern    bool    do_lrot;        /* enable loop rotations */
  104. extern    bool    gflag;            /* set when using the debugger */
  105. extern    bool    verbose;
  106.  
  107. /*
  108.  * Optimization stats
  109.  */
  110. extern    int    s_bdel;
  111. extern    int    s_badd;
  112. extern    int    s_brev;
  113. extern    int    s_peep1;
  114. extern    int    s_peep2;
  115. extern    int    s_peep3;
  116. extern    int    s_idel;
  117. extern    int    s_reg;
  118. extern    int    s_lrot;
  119.  
  120. /*
  121.  * These are set after calling readline.
  122.  */
  123. extern    char    *t_line;    /* text of the last line */
  124. extern    char    *t_lab;        /* label (if any) on the last line */
  125. extern    char    *t_op;        /* opcode */
  126. extern    char    *t_arg;        /* arguments */
  127.  
  128.  
  129. extern    char    *opnames[];    /* mnemonics for the instructions */
  130.  
  131. extern    BLOCK    *fhead;        /* head of the current function */
  132.  
  133. /*
  134.  * Function declarations
  135.  */
  136.  
  137. /*
  138.  * branch.c
  139.  */
  140. extern    void    bopt();
  141.  
  142. /*
  143.  * data.c
  144.  */
  145. extern    int    reg_ref(), reg_set();
  146. extern    bool    sets(), refs(), uses();
  147.  
  148. /*
  149.  * health.c
  150.  */
  151. extern    void    rhealth(), bprep();
  152.  
  153. /*
  154.  * inst.c
  155.  */
  156. extern    void    addinst(), delinst(), putinst();
  157. extern    bool    opeq();
  158.  
  159. /*
  160.  * io.c
  161.  */
  162. extern    bool    readline();
  163.  
  164. /*
  165.  * peep1.c
  166.  */
  167. extern    void    peep();
  168.  
  169. /*
  170.  * reg.c
  171.  */
  172. extern    void    addvar(), setreg(), clrvar();
  173.  
  174. /*
  175.  * util.c
  176.  */
  177. extern    char    *alloc();
  178. extern    char    *strsave();
  179.  
  180. /*
  181.  * sym.c
  182.  */
  183. extern    void    freeop(), freesym();
  184. extern    BLOCK    *getsym(), *mksym();
  185. extern    char    *mktmp();
  186.